package cn.edu.hstc.wm.ui;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import cn.edu.hstc.wm.R;
import cn.edu.hstc.wm.service.FeedbackService;
import cn.edu.hstc.wm.ui.base.BaseActivity;

/**
 * @ClassName: UserFeedbackRecord
 * @Description:用户反馈记录
 * 
 * @ModificationHistory
 */
public class UserFeedbackRecord extends BaseActivity implements OnClickListener {

	private ListView mListView;
	private SimpleAdapter mAdapter;

	private List<Map<String, String>> dataList;
	private String[] from;
	private int[] to;

	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.user_feedback_record);

		initView();

		initListView();
	}

	private void initView() {
		ImageView backView = (ImageView) findViewById(R.id.iv_feedback_record_back);
		ImageView contentView = (ImageView) findViewById(R.id.iv_feedback_record_content);

		backView.setOnClickListener(this);
		contentView.setOnClickListener(this);

	}

	private void initListView() {
		mListView = (ListView) findViewById(R.id.lv_feedback_record_list);
		initData();

		mAdapter = new SimpleAdapter(this, dataList, R.layout.user_feedback_record_item, from, to);
		mListView.setAdapter(mAdapter);
	}

	private void initData() {
		from = new String[] { "content", "time" };
		to = new int[] { R.id.tv_feedback_content, R.id.tv_feedback_time };
		
		dataList = FeedbackService.getRecord(this);
		if (dataList==null) {
			dataList = new ArrayList<Map<String,String>>();
			
			Map<String, String> map = new HashMap<String, String>();
			map.put("content", "还没有反馈记录");
			map.put("time", "" + new Date());
			dataList.add(map);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_feedback_record_back:
			setResult(Activity.RESULT_OK);
			finish();
			break;

		case R.id.iv_feedback_record_content:
			finish();
			break;

		default:
			break;
		}
	}

}
